package top.codedance.iotp.server.net.handle.subhandle.controller.http.async;

import top.codedance.iotp.common.constent.Command;
import top.codedance.iotp.server.ServerApplication;
import top.codedance.iotp.server.net.WsServer;
import top.codedance.iotp.server.net.handle.WsChannelHandler;
import top.codedance.iotp.server.net.handle.subhandle.controller.http.AbsractWsReceiveHandler;
import org.apache.log4j.Logger;

public class ClientsStatusReceiverHandler extends AbsractWsReceiveHandler {
    private static final Logger logger = ServerApplication.getLogger(ClientsStatusReceiverHandler.class);

    @Override
    public void receive(String deviceId, String clientId, Integer instance, String data) {
        if(WsChannelHandler.wsIsActive(clientId)) {
            WsChannelHandler.wsSend(clientId, data);
        }else{
            if(WsServer.localTaskClients.containsKey(Command.ASYNC_CSTATUS_COMMAND_RECEIVE)){
                WsServer.localTaskClients.get(Command.ASYNC_CSTATUS_COMMAND_RECEIVE).remove(clientId);
            }
        }
        logger.debug("ClientsStatusReceiverHandler");
    }
}
